package com.dailyblue.java.thread.四个方法;

import lombok.SneakyThrows;

// sleep
public class DemoA {


    static class A1 implements Runnable {
        private A2 a2;

        public void setA2(A2 a2) {
            this.a2 = a2;
        }

        @Override
        public void run() {
            a2.a();
        }
    }

    static class A2 {
        @SneakyThrows
        public synchronized void a() {
            System.out.println(Thread.currentThread().getName() + "正在执行a方法！");
            Thread.sleep(5000);
            System.out.println(Thread.currentThread().getName() + "继续执行a方法！");
        }
    }

    @SneakyThrows
    public static void main(String[] args) {
        A2 a = new A2();
        A1 a1 = new A1();
        A1 a2 = new A1();
        a1.setA2(a);
        a2.setA2(a);
        Thread t1 = new Thread(a1);
        Thread t2 = new Thread(a2);
        t1.start();
        Thread.sleep(1000);
        t2.start();
    }
}
